package com.alibaba.citrus.cr.mn.order.center.facade.service.impl;

import com.alibaba.citrus.cr.common.annotation.FacadeInvoker;
import com.alibaba.citrus.cr.common.enums.GeneralStatusEnum;
import com.alibaba.citrus.cr.common.enums.ordercenter.*;
import com.alibaba.citrus.cr.common.exception.FunctionException;
import com.alibaba.citrus.cr.common.lock.SaleRedisLock;
import com.alibaba.citrus.cr.common.util.DateUtils;
import com.alibaba.citrus.cr.mn.order.center.common.SetOrderTag;
import com.alibaba.citrus.cr.mn.order.center.common.util.AssertUtils;
import com.alibaba.citrus.cr.mn.order.center.common.util.StopWatchUtils;
import com.alibaba.citrus.cr.mn.order.center.common.util.TrimUtils;
import com.alibaba.citrus.cr.mn.order.center.facade.adapter.BaseDataServiceAdapter;
import com.alibaba.citrus.cr.mn.order.center.facade.adapter.DictionaryVerifyAdapter;
import com.alibaba.citrus.cr.mn.order.center.facade.function.asynctask.AsyncTaskCreateService;
import com.alibaba.citrus.cr.mn.order.center.facade.function.check.AbstractOrderParamsCheckService;
import com.alibaba.citrus.cr.mn.order.center.facade.function.check.CommonCheck;
import com.alibaba.citrus.cr.mn.order.center.facade.function.common.*;
import com.alibaba.citrus.cr.mn.order.center.facade.function.convert.AtomOrderDOToReturnOrderAtomQueryResponseConvertor;
import com.alibaba.citrus.cr.mn.order.center.facade.function.dataobject.AtomOrderDO;
import com.alibaba.citrus.cr.mn.order.center.facade.repository.AtomOrderQueryRepository;
import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.crb2btradecenter.domain.order.dto.QueryByOrderNosRequest;
import com.epoch.app.crb2btradecenter.enums.OrderStatus;
import com.epoch.app.crb2btradecenter.model.dto.PageQueryOrderEsListRequest4OrderCenter;
import com.epoch.app.crb2btradecenter.model.dto.PageQuerySaleOrderDetailGroupRequest;
import com.epoch.app.crb2btradecenter.model.enums.MessageTaskTypeEnum;
import com.epoch.app.crb2btradecenter.obtcsaleorderindex.model.ObtcSaleOrderIndex;
import com.epoch.app.crb2btradecenter.obtcsaleorderindex.service.ObtcSaleOrderIndexService;
import com.epoch.app.crb2btradecenter.obtcsaleorderlineindex.model.ObtcSaleOrderLineIndex;
import com.epoch.app.crb2btradecenter.obtcsaleorderlineindex.service.ObtcSaleOrderLineIndexService;
import com.epoch.app.mnordercenter.contants.MnOrderCenterConstants;
import com.epoch.app.mnordercenter.model.dto.*;
import com.epoch.app.mnordercenter.orderbaserequest.*;
import com.epoch.app.mnordercenter.returnordergroup.service.ReturnOrderGroupService;
import com.google.common.collect.Lists;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.alibaba.citrus.cr.mn.order.center.common.constants.RedisLockConstants.*;

@Primary
@Component
public class ReturnOrderGroupServiceImpl implements ReturnOrderGroupService {

    private static final Log log = Log.getLogger(ReturnOrderGroupServiceImpl.class);

    @Resource
    private BaseDataServiceAdapter baseDataServiceAdapter;
    @Resource
    private DictionaryVerifyAdapter dictionaryVerifyAdapter;
    @Resource
    private AtomOrderQueryRepository atomOrderQueryRepository;
    @Resource
    private ObtcSaleOrderIndexService obtcSaleOrderIndexService;
    @Resource
    private ObtcSaleOrderLineIndexService obtcSaleOrderLineIndexService;
    @Resource
    private AsyncTaskCreateService asyncTaskCreateService;
    @Resource(name = "returnOrderGroupCloseService")
    private OrderBizCloseService returnOrderGroupCloseService;
    @Resource(name = "returnOrderBizCreateParamsCheck")
    private AbstractOrderParamsCheckService returnOrderBizCreateParamsCheck;
    @Resource(name = "returnOrderBizCreateService")
    private OrderBizCreateService<ReturnOrderBizBatchCreateRequest, ReturnOrderAtomBatchCreateRequest, OrderAtomCreateResponse> returnOrderBizCreateService;
    @Resource(name = "returnOrderBizUpdateService")
    private OrderBizUpdateService<OrderBizUpdateRequest, OrderAtomUpdateRequest, OrderAtomUpdateResponse> returnOrderBizUpdateService;
    @Resource(name = "returnOrderBizSubmitService")
    private OrderBizSubmitService returnOrderBizSubmitService;
    @Resource(name = "returnOrderAtomCancelService")
    private OrderAtomCancelService returnOrderAtomCancelService;
    @Resource
    private CommonCheck commonCheck;
    @Resource
    private SendMsgService sendMsgService;

    @Override
    @FacadeInvoker(value = "退货订单批量创建", errorCode = "OC-02-001-01-16-006")
    public Result<OrderBizCreateResponse> batchCreate(ReturnOrderAtomBatchCreateRequest request) {
        AssertUtils.isTrue(StringUtils.isBlank(request.getReqNo()), "OC-01-001-01-15-001", "请求编码");
        AssertUtils.lengthCheck(request.getReqNo(), 128, true, "OC-01-001-01-15-004", "请求编码");

        log.info("ReturnOrderGroupServiceImpl#batchCreate request={}", JSON.toJSONString(request));
        String lockKey = RETURN_ORDER_GROUP_PREFIX + request.getReqNo();
        log.info("ReturnOrderGroupServiceImpl#batchCreate lockKey={}", lockKey);

        try (SaleRedisLock lock = new SaleRedisLock(CACHE_CODE, lockKey, TIMEOUT_MSECS, EXPIRE_MSECS, SLEEP_MILLIS)) {
            if (!lock.lock()) {
                log.error("ReturnOrderGroupServiceImpl#batchCreate 分布式锁获取失败 lockKey={}", lockKey);
                return Result.fail("OC-00-000-01-99-002", "分布式锁获取失败");
            }
            AssertUtils.isTrue(CollectionUtils.isEmpty(request.getOrderList()), "OC-01-001-01-15-001", "单据列表");

            // 移除入参里的前后空格
            StopWatchUtils.start("订单中心商业创建", "removeSpace");
            TrimUtils.removeSpace(request);
            StopWatchUtils.stop();

            StopWatchUtils.start("订单中心商业创建", "paramsInvalidCheck");
            request.setOrderCategoryCode(OrderCategoryEnum.GROUP.getCode());
            request.getOrderList().forEach(order -> {
                if (StringUtils.isNotBlank(request.getFromSys())) {
                    order.setFromSys(request.getFromSys());
                }
                if (StringUtils.isNotBlank(request.getBusinessType())) {
                    order.setBusinessType(request.getBusinessType());
                }
                if (StringUtils.isNotBlank(request.getBusinessUnitCode())) {
                    order.setBusinessUnitCode(request.getBusinessUnitCode());
                }
                if (StringUtils.isBlank(order.getFulfillmentTypeCode())) {
                    order.setFulfillmentTypeCode(FulfillmentTypeEnum.EXTERNAL_TO_EXTERNAL.getCode());
                }
                if (StringUtils.isBlank(order.getFulfillmentPriority())) {
                    order.setFulfillmentPriority(FulfillmentPriorityEnum.NORMAL.getCode());
                }
                if (StringUtils.isBlank(order.getAutoFulfillment())) {
                    order.setAutoFulfillment(Boolean.TRUE.toString());
                }
                if (Objects.isNull(order.getIsSubmit())) {
                    order.setIsSubmit(Boolean.TRUE);
                }

                // 设置默认值
                order.setCheckStock(Boolean.FALSE);
                order.setCheckCredit(Boolean.FALSE);
                order.setCheckCreditB(Boolean.FALSE);
                order.setOrderCategoryCode(OrderCategoryEnum.GROUP.getCode());
            });
            returnOrderBizCreateParamsCheck.paramsInvalidCheck(request.getOrderList(), new ArrayList());
            StopWatchUtils.stop();

            StopWatchUtils.start("订单中心商业创建", "createAsyncTask");
            String batchTaskId = asyncTaskCreateService.createAsyncTask(request.getFromSys() + "#" + request.getReqNo(),
                    request.getFromSys(), JSON.toJSONString(request), MessageTaskTypeEnum.OC_RETURN_ORDER_BATCH_CREATE);
            StopWatchUtils.stop();

            OrderBizCreateResponse orderBizCreateResponse = new OrderBizCreateResponse();
            orderBizCreateResponse.setBatchTaskId(batchTaskId);
            return Result.success(orderBizCreateResponse, "", "");
        } catch (Exception e) {
            log.error("ReturnOrderGroupServiceImpl#batchCreate error", e);
            throw e;
        } finally {
            StopWatchUtils.print("ReturnOrderGroupServiceImpl#batchCreate");
        }
    }

    @Override
    @FacadeInvoker(value = "退货订单批量提交", errorCode = "OC-02-001-01-16-018")
    public Result<List<OrderAtomSubmitResponse>> batchSubmit(OrderBizBatchSubmitRequest request) {
        log.info("ReturnOrderGroupServiceImpl#batchSubmit request={}", JSON.toJSONString(request));
        String lockKey = RETURN_ORDER_GROUP_PREFIX + DigestUtils.md5Hex(JSON.toJSONString(request));
        log.info("ReturnOrderGroupServiceImpl#batchSubmit lockKey={}", lockKey);

        try (SaleRedisLock lock = new SaleRedisLock(CACHE_CODE, lockKey, TIMEOUT_MSECS, EXPIRE_MSECS, SLEEP_MILLIS)) {
            if (!lock.lock()) {
                log.error("ReturnOrderGroupServiceImpl#batchSubmit 分布式锁获取失败 lockKey={}", lockKey);
                return Result.fail("OC-00-000-01-99-002", "分布式锁获取失败");
            }
            AssertUtils.isTrue(CollectionUtils.isEmpty(request.getOrderList()), "OC-01-001-01-15-001", "单据列表");

            for (OrderAtomSubmitRequest salesOrder : request.getOrderList()) {
                salesOrder.setCheckStock(Boolean.FALSE);
                salesOrder.setCheckCredit(Boolean.FALSE);
                salesOrder.setCheckCreditB(Boolean.FALSE);
            }
            request.setOrderCategoryCode(OrderCategoryEnum.GROUP.getCode());

            List<OrderAtomSubmitResponse> resp = returnOrderBizSubmitService.batchSubmit(request);
            if (CollectionUtils.isNotEmpty(resp)) {
                // 发送消息通知来源系统
                List<PushOrderInfoToMnSideRequestOrderInfo> pushOrderInfoList = new ArrayList<>();
                for (OrderAtomSubmitResponse submitResponse : resp) {
                    pushOrderInfoList.add(PushOrderInfoToMnSideRequestOrderInfo.builder()
                            .salesOrderNo(submitResponse.getSalesOrderNo())
                            .orderStatus(SalesOrderPushStatusEnum.FAIL_UPDATE.getOrderStatusCode())
                            .message(submitResponse.getMessage())
                            .build());
                }
                // 发送kafka消息通知应用端处理结果
//                sendMsgService.sendMsgToNYK(pushOrderInfoList);
                CommonAsyncMessageResponse commonAsyncMessageResponse = new CommonAsyncMessageResponse();
                commonAsyncMessageResponse.setEventCode(AsyncMessageEventEnum.RETURN_ORDER_UPDATE.getValue());
                commonAsyncMessageResponse.setEventName(AsyncMessageEventEnum.RETURN_ORDER_UPDATE.getLabel());
                commonAsyncMessageResponse.setEventTime(String.valueOf(new Date().getTime()));
                commonAsyncMessageResponse.setFromSys(request.getFromSys());
                commonAsyncMessageResponse.setBusinessUnitCode(request.getBusinessUnitCode());
                commonAsyncMessageResponse.setData(pushOrderInfoList);
                sendMsgService.sendMsgToSendKafka(commonAsyncMessageResponse);
                log.info("ReturnOrderGroupServiceImpl#batchSubmit sendMsgToSendKafka message={}", commonAsyncMessageResponse);
            }
            return Result.success(resp, "", "");
        } catch (Exception e) {
            log.error("ReturnOrderGroupServiceImpl#batchSubmit error", e);
            throw e;
        } finally {
            StopWatchUtils.print("ReturnOrderGroupServiceImpl#batchSubmit");
        }
    }

    @Override
    @FacadeInvoker(value = "退货订单创建", errorCode = "OC-02-001-01-16-006")
    public Result<OrderAtomCreateResponse> create(ReturnOrderAtomCreateRequest request) {
        log.info("ReturnOrderGroupServiceImpl#create request={}", JSON.toJSONString(request));
        String lockKey = RETURN_ORDER_GROUP_PREFIX + DigestUtils.md5Hex(JSON.toJSONString(request));
        log.info("ReturnOrderGroupServiceImpl#create lockKey={}", lockKey);

        try (SaleRedisLock lock = new SaleRedisLock(CACHE_CODE, lockKey, TIMEOUT_MSECS, EXPIRE_MSECS, SLEEP_MILLIS)) {
            if (!lock.lock()) {
                log.error("ReturnOrderGroupServiceImpl#create 分布式锁获取失败 lockKey={}", lockKey);
                return Result.fail("OC-00-000-01-99-002", "分布式锁获取失败");
            }

            // 移除入参里的前后空格
            StopWatchUtils.start("订单中心同步创建", "removeSpace");
            TrimUtils.removeSpace(request);
            StopWatchUtils.stop();

            StopWatchUtils.start("订单中心同步创建", "paramsInvalidCheck");
            AssertUtils.lengthCheck(request.getReqNo(), 128, true, "OC-01-001-01-15-004", "请求编码");

            // 设置默认值
            request.setCheckStock(Boolean.FALSE);
            request.setCheckCredit(Boolean.FALSE);
            request.setCheckCreditB(Boolean.FALSE);
            request.setOrderCategoryCode(OrderCategoryEnum.GROUP.getCode());

            if (StringUtils.isBlank(request.getFulfillmentTypeCode())) {
                request.setFulfillmentTypeCode(FulfillmentTypeEnum.EXTERNAL_TO_EXTERNAL.getCode());
            }
            if (StringUtils.isBlank(request.getFulfillmentPriority())) {
                request.setFulfillmentPriority(FulfillmentPriorityEnum.NORMAL.getCode());
            }
            if (StringUtils.isBlank(request.getAutoFulfillment())) {
                request.setAutoFulfillment(Boolean.TRUE.toString());
            }
            if (Objects.isNull(request.getIsSubmit())) {
                request.setIsSubmit(Boolean.TRUE);
            }

            returnOrderBizCreateParamsCheck.paramsInvalidCheck(Lists.newArrayList(request), new ArrayList());
            StopWatchUtils.stop();

            StopWatchUtils.start("订单中心同步创建", "createAsyncTask");
            ReturnOrderBizCreateRequest createRequest = new ReturnOrderBizCreateRequest();
            BeanUtils.copyProperties(request, createRequest);
            ReturnOrderBizBatchCreateRequest batchCreateRequest = new ReturnOrderBizBatchCreateRequest();
            batchCreateRequest.setOrderList(Lists.newArrayList(createRequest));
            List<OrderAtomCreateResponse> createResponses = returnOrderBizCreateService.batchCreate(batchCreateRequest);
            StopWatchUtils.stop();

            OrderAtomCreateResponse orderAtomCreateResponse = createResponses.get(0);
            if (StringUtils.isNotBlank(orderAtomCreateResponse.getErrorCode())) {
                return Result.fail(orderAtomCreateResponse, orderAtomCreateResponse.getErrorCode(), orderAtomCreateResponse.getMessage());
            } else {
                return Result.success(orderAtomCreateResponse, "", "");
            }
        } catch (Exception e) {
            log.error("ReturnOrderGroupServiceImpl#create error", e);
            throw e;
        } finally {
            StopWatchUtils.print("ReturnOrderGroupServiceImpl#create");
        }
    }

    @Override
    @FacadeInvoker(value = "退货订单详情查询", errorCode = "OC-01-003-01-16-008")
    public Result<QueryReturnResponse> query(QueryReturnOrderRequest request) {
        paramQueryCheck(request);
        //参数组装
        QueryByOrderNosRequest queryRequest = QueryByOrderNosRequest.builder().build();
        queryRequest.setPage(1);
        queryRequest.setSize(10);
        queryRequest.setSalesOrderNo(Collections.singletonList(request.getSalesOrderNo()));
        queryRequest.setBusinessUnitOutCode(request.getBusinessUnitCode());
        queryRequest.setOrderTag(SetOrderTag.RETURN);
        queryRequest.setFromSys(request.getFromSys());
        queryRequest.setBusinessType(Integer.parseInt(request.getBusinessType()));

        Result<List<AtomOrderDO>> listResult = atomOrderQueryRepository.queryByOrderNos(queryRequest);
        log.info("ReturnOrder_query_Request={}，listResult={}", JSONObject.toJSON(request), JSONObject.toJSONString(listResult));

        if (CollectionUtils.isEmpty(listResult.getResult())) {
            throw new FunctionException("OC-02-001-01-15-008", request.getSalesOrderNo());
        }

        QueryReturnResponse response = AtomOrderDOToReturnOrderAtomQueryResponseConvertor.AtomOrderDOToQueryReturnResponseConvert(listResult.getResult());

        Result<QueryReturnResponse> success = Result.success(response, "", "");
        success.setTotal(listResult.getTotal());
        return success;
    }

    @Override
    @FacadeInvoker(value = "退货订单更新", errorCode = "OC-02-001-01-16-019")
    public Result<OrderAtomUpdateResponse> update(OrderBizUpdateRequest request) {
        log.info("ReturnOrderGroupServiceImpl#update request={}", JSON.toJSONString(request));
        String lockKey = RETURN_ORDER_GROUP_PREFIX + request.getSalesOrderNo();
        log.info("ReturnOrderGroupServiceImpl#update lockKey={}", lockKey);
        try (SaleRedisLock lock = new SaleRedisLock(CACHE_CODE, lockKey, TIMEOUT_MSECS, EXPIRE_MSECS, SLEEP_MILLIS)) {
            if (!lock.lock()) {
                log.error("ReturnOrderGroupServiceImpl#update 分布式锁获取失败 lockKey={}", lockKey);
                return Result.fail("OC-00-000-01-99-002", "分布式锁获取失败");
            }
            request.setOrderCategoryCode(OrderCategoryEnum.GROUP.getCode());
            request.setCheckStock(Boolean.FALSE);
            request.setCheckCredit(Boolean.FALSE);
            request.setCheckCreditB(Boolean.FALSE);
            OrderAtomUpdateResponse response = returnOrderBizUpdateService.update(request);
            if (StringUtils.isNotBlank(response.getErrorCode())) {
                return Result.fail(response, "", "");
            }
            return Result.success(response, "", "");
        } catch (Exception e) {
            log.error("ReturnOrderGroupServiceImpl#update error", e);
            throw e;
        } finally {
            StopWatchUtils.print("ReturnOrderGroupServiceImpl#update");
        }
    }

    @Override
    @FacadeInvoker(value = "退货订单取消", errorCode = "OC-02-001-01-16-017")
    public Result<List<OrderAtomCancelResponse>> batchCancel(OrderAtomBatchCancelRequest request) {
        log.info("ReturnOrderGroupServiceImpl#batchCancel request={}", JSON.toJSONString(request));
        String lockKey = RETURN_ORDER_GROUP_PREFIX + DigestUtils.md5Hex(JSON.toJSONString(request));
        log.info("ReturnOrderGroupServiceImpl#batchCancel lockKey={}", lockKey);

        try (SaleRedisLock lock = new SaleRedisLock(CACHE_CODE, lockKey, TIMEOUT_MSECS, EXPIRE_MSECS, SLEEP_MILLIS)) {
            if (!lock.lock()) {
                log.error("ReturnOrderGroupServiceImpl#batchCancel 分布式锁获取失败 lockKey={}", lockKey);
                return Result.fail("OC-00-000-01-99-002", "分布式锁获取失败");
            }
            AssertUtils.isTrue(StringUtils.isBlank(request.getModifierCode()), "OC-01-001-01-15-001", "修改人工号");
            AssertUtils.lengthCheck(request.getModifierCode(), 50, true, "OC-01-001-01-15-004", "修改人工号");
            AssertUtils.isTrue(CollectionUtils.isEmpty(request.getOrderList()), "OC-01-001-01-15-001", "单据列表");
            Modifiers modifiers = commonCheck.invalidModifier(request.getModifierCode());
            request.getOrderList().forEach(order -> {
                        order.setModifierCode(modifiers.getWorkId());
                        order.setModifierName(modifiers.getName());
                    }
            );
            List<OrderAtomCancelResponse> responseList = returnOrderAtomCancelService.batchCancel(request, OrderCategoryEnum.GROUP.getCode());
            responseList.forEach(res -> {
                if (Objects.isNull(res.getSuccess())) {
                    res.setSuccess(Boolean.FALSE);
                }
            });
            return Result.success(responseList, "", "");
        } catch (Exception e) {
            log.error("ReturnOrderGroupServiceImpl#batchCancel error", e);
            throw e;
        } finally {
            StopWatchUtils.print("ReturnOrderGroupServiceImpl#batchCancel");
        }
    }

    @Override
    @FacadeInvoker(value = "退货订单关闭", errorCode = "OC-02-001-01-16-013")
    public Result<List<OrderAtomCloseResponse>> batchClose(OrderBizBatchCloseRequest request) {
        log.info("ReturnOrderGroupServiceImpl#batchClose request={}", JSON.toJSONString(request));
        String lockKey = RETURN_ORDER_GROUP_PREFIX + DigestUtils.md5Hex(JSON.toJSONString(request));
        log.info("ReturnOrderGroupServiceImpl#batchClose lockKey={}", lockKey);

        try (SaleRedisLock lock = new SaleRedisLock(CACHE_CODE, lockKey, TIMEOUT_MSECS, EXPIRE_MSECS, SLEEP_MILLIS)) {
            if (!lock.lock()) {
                log.error("ReturnOrderGroupServiceImpl#batchClose 分布式锁获取失败 lockKey={}", lockKey);
                return Result.fail("OC-00-000-01-99-002", "分布式锁获取失败");
            }
            request.setOrderCategoryCode(OrderCategoryEnum.GROUP.getCode());
            Result<List<OrderAtomCloseResponse>> result = returnOrderGroupCloseService.batchClose(request);
            return result;
        } catch (Exception e) {
            log.error("ReturnOrderGroupServiceImpl#batchClose error", e);
            throw e;
        } finally {
            StopWatchUtils.print("ReturnOrderGroupServiceImpl#batchClose");
        }
    }

    @Override
    @FacadeInvoker(value = "退货订单主单分页查询", errorCode = "OC-01-003-01-16-008")
    public Result<List<ReturnOrderGroupPageQueryResponse>> pageQuery(ReturnOrderGroupPageQueryRequest request) {
        TrimUtils.removeSpace(request);
        //校验参数
        paramPageQueryCheck(request);
        //入参转换
        SalesOrderAtomPageQueryRequest salesOrderAtomPageQueryRequest = AtomOrderDOToReturnOrderAtomQueryResponseConvertor.convertPageQueryRequest(request);

        //调用查询接口
        salesOrderAtomPageQueryRequest.setOrderCategoryCode(OrderCategoryEnum.GROUP.getCode());
        if (salesOrderAtomPageQueryRequest.getPage() == null) {
            salesOrderAtomPageQueryRequest.setPage(1);
        }
        if (salesOrderAtomPageQueryRequest.getSize() == null) {
            salesOrderAtomPageQueryRequest.setSize(10);
        }
        log.error("returnOrderAtomPageQueryRequest参数:{}", JSON.toJSONString(salesOrderAtomPageQueryRequest));

        PageQueryOrderEsListRequest4OrderCenter esRequest = buildPageQueryOrderEsListRequest(salesOrderAtomPageQueryRequest);

        esRequest.setBusinessUnitOutCode(request.getBusinessUnitCode());
        esRequest.setBusinessUnitCode(null);
        log.info("Return_Order_Page_Main_Request request={}", JSONObject.toJSON(esRequest));
        Result<List<ObtcSaleOrderIndex>> listResult = obtcSaleOrderIndexService.pageQueryOrderList4OrderCenter(esRequest);
        log.error("listResult索引结果：{}", JSON.toJSONString(listResult));

        Result<List<ReturnOrderGroupPageQueryResponse>> pageResult = new Result<>();
        pageResult.setTotal(listResult.getTotal());
        pageResult.setErrorCode("");
        pageResult.setMessage("");

        if (listResult.isSuccess()) {
            //出参转换
            List<ReturnOrderGroupPageQueryResponse> queryResponsesList = AtomOrderDOToReturnOrderAtomQueryResponseConvertor.convertPageQueryResponse(listResult);
            pageResult.setSuccess(Boolean.TRUE);
            pageResult.setResult(queryResponsesList);
        } else {
            pageResult.setSuccess(Boolean.FALSE);
            pageResult.setMessage("分页查询退货列表失败");
            pageResult.setErrorCode("OC-01-001-01-16-056");
        }

        return pageResult;
    }

    @Override
    @FacadeInvoker(value = "退货订单明细分页查询", errorCode = "OC-01-003-01-16-008")
    public Result<List<ReturnOrderGroupDetailPageQueryResponse>> batchQueryLine(ReturnOrderGroupDetailPageQueryRequest request) {
        TrimUtils.removeSpace(request);
        //校验参数
        paramDetailPageQueryCheck(request);
        if (request.getPage() == null) {
            request.setPage(1);
        }
        if (request.getSize() == null) {
            request.setSize(10);
        }
        //入参转换
        PageQuerySaleOrderDetailGroupRequest esRequest = AtomOrderDOToReturnOrderAtomQueryResponseConvertor.convertDetailPageQueryRequest(request);
        esRequest.setOrderCategoryCode(OrderCategoryEnum.GROUP.getCode());
        esRequest.setOrderTag(SetOrderTag.RETURN);

        log.info("ReturnOrderGroupQueryServiceImpl#pageQueryByEs esRequest:{};", JSON.toJSONString(esRequest));
        Result<List<ObtcSaleOrderLineIndex>> listResult = obtcSaleOrderLineIndexService.pageOrderLineList(esRequest);
        log.info("ReturnOrderGroupQueryServiceImpl#pageQueryByEs listResult:{};", JSON.toJSONString(listResult));

        List<ReturnOrderGroupDetailPageQueryResponse> response = AtomOrderDOToReturnOrderAtomQueryResponseConvertor.convertDetailPageQueryResponse(listResult);

        Result<List<ReturnOrderGroupDetailPageQueryResponse>> success = Result.success(response, "", "");
        success.setTotal(listResult.getTotal());
        return success;
    }

    private void paramDetailPageQueryCheck(ReturnOrderGroupDetailPageQueryRequest request) {
        //必填项校验
        AssertUtils.isTrue(StringUtils.isBlank(request.getBusinessType()), "OC-01-001-01-15-001", "业态编码");
        //长度校验
        if (CollectionUtils.isNotEmpty(request.getFromSysList())) {
            AssertUtils.isTrue(request.getFromSysList().size() > 10, "OC-01-001-01-15-004", "来源系统编码集合", request.getFromSysList().size(), "10");
            checkItemLength(request.getFromSysList(), 50, "来源系统编码");
            request.getFromSysList().forEach(fromSys -> {
                dictionaryVerifyAdapter.verifyDictionary(DictionaryTypeEnum.FROM_SYS.getCode(), fromSys, new FunctionException("OC-01-001-01-15-006", "来源系统编码"));
            });
        }
        AssertUtils.lengthCheck(request.getBusinessType(), 10, true, "OC-01-001-01-15-004", "业态编码");
        List<DictionaryResponse> businessTypeResponseList = baseDataServiceAdapter.queryDictionarys(DictionaryTypeEnum.BUSINESS_TYPE.getCode());
        Map<String, DictionaryResponse> businessTypeMap = businessTypeResponseList.stream().collect(Collectors.toMap(DictionaryResponse::getCode, Function.identity(), (k1, k2) -> k2));
        if (Objects.isNull(businessTypeMap.get(request.getBusinessType()))) {
            throw new FunctionException("OC-01-001-01-15-006", "业态编码");
        }
        if (CollectionUtils.isNotEmpty(request.getBusinessUnitCodeList())) {
            AssertUtils.isTrue(request.getBusinessUnitCodeList().size() > 10, "OC-01-001-01-15-004", "业务单元编码集合", request.getBusinessUnitCodeList().size(), "10");
            checkItemLength(request.getBusinessUnitCodeList(), 50, "业务单元编码");
            request.getBusinessUnitCodeList().forEach(businessUnitCode -> {
                dictionaryVerifyAdapter.verifyDictionary(DictionaryTypeEnum.BUSINESS_UNIT_CODE.getCode(), businessUnitCode, new FunctionException("OC-01-001-01-15-006", "业务单元编码"));
            });
        }
        if (Objects.nonNull(request.getPage())) {
            AssertUtils.isTrue(request.getPage() > MnOrderCenterConstants.MAX_PAGE().intValue(), "OC-01-001-01-15-009", "页数", "最大" + MnOrderCenterConstants.MAX_PAGE().intValue());
            AssertUtils.isTrue(request.getPage() <= 0, "OC-01-001-01-15-009", "页数", "最小值为1");
        }
        if (Objects.nonNull(request.getSize())) {
            AssertUtils.isTrue(request.getSize() > MnOrderCenterConstants.MAX_SIZE().intValue(), "OC-01-001-01-15-009", "分页条数", "最大" + MnOrderCenterConstants.MAX_SIZE().intValue());
            AssertUtils.isTrue(request.getSize() <= 0, "OC-01-001-01-15-009", "分页条数", "最小值为1");
        }
        if (CollectionUtils.isNotEmpty(request.getOrderChannelCodeList())) {
            AssertUtils.isTrue(request.getOrderChannelCodeList().size() > 10, "OC-01-001-01-15-004", "订单渠道编码集合", request.getOrderChannelCodeList().size(), "10");
            checkItemLength(request.getOrderChannelCodeList(), 50, "订单渠道编码");
            List<String> checkExistList = request.getOrderChannelCodeList().stream().filter(x -> !OrderChannelEnum.codes().contains(x)).collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "订单渠道编码");
        }
        if (CollectionUtils.isNotEmpty(request.getSalesOrderNoList())) {
            AssertUtils.isTrue(request.getSalesOrderNoList().size() > 50, "OC-01-001-01-15-004", "退货订单号集合", request.getSalesOrderNoList().size(), 50);
            checkItemLength(request.getSalesOrderNoList(), 50, "退货订单号");
        }
        if (CollectionUtils.isNotEmpty(request.getOriginalOrderNoList())) {
            AssertUtils.isTrue(request.getOriginalOrderNoList().size() > 50, "OC-01-001-01-15-004", "原销售订单单号集合", request.getOriginalOrderNoList().size(), 50);
            request.getOriginalOrderNoList().forEach(x -> AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "原销售订单单号"));
        }
        if (CollectionUtils.isNotEmpty(request.getSourceOrderNoList())) {
            AssertUtils.isTrue(request.getSourceOrderNoList().size() > 50, "OC-01-001-01-15-004", "来源单号集合", request.getSourceOrderNoList().size(), 50);
            request.getSourceOrderNoList().forEach(x -> AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "来源单号"));
        }
        if (CollectionUtils.isNotEmpty(request.getOutOrderNoList())) {
            AssertUtils.isTrue(request.getOutOrderNoList().size() > 50, "OC-01-001-01-15-004", "外部单号集合", request.getOutOrderNoList().size(), 50);
            request.getOutOrderNoList().forEach(x -> AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "外部单号"));
        }
        AssertUtils.lengthCheck(request.getProductGroupCode(), 50, false, "OC-01-001-01-15-004", "产品组编码");
        AssertUtils.lengthCheck(request.getBusinessChannelCode(), 50, false, "OC-01-001-01-15-004", "业务渠道编码");
        AssertUtils.lengthCheck(request.getSalesOrganizationCode(), 50, false, "OC-01-001-01-15-004", "销售组织编码");
        AssertUtils.lengthCheck(request.getShipToPartyCode(), 50, false, "OC-01-001-01-15-004", "送达方编码");
        AssertUtils.lengthCheck(request.getCustomerCode(), 50, false, "OC-01-001-01-15-004", "售达方编码");
        if (CollectionUtils.isNotEmpty(request.getSalesChannelCodeList())) {
            AssertUtils.isTrue(request.getSalesChannelCodeList().size() > 10, "OC-01-001-01-15-004", "销售渠道编码集合", request.getSalesChannelCodeList().size(), 10);
            request.getSalesChannelCodeList().forEach(x -> {
                AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "销售渠道编码");
            });
        }
        if (CollectionUtils.isNotEmpty(request.getSalesDepartmentCodeList())) {
            AssertUtils.isTrue(request.getSalesDepartmentCodeList().size() > 10, "OC-01-001-01-15-004", "销售部门编码集合", request.getSalesDepartmentCodeList().size(), 10);
            request.getSalesDepartmentCodeList().forEach(x -> {
                AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "销售部门编码");
            });
        }
        AssertUtils.lengthCheck(request.getCustomerGroup(), 50, false, "OC-01-001-01-15-004", "客户组编码");
        if (CollectionUtils.isNotEmpty(request.getSalesOrderTypeList())) {
            AssertUtils.isTrue(request.getSalesOrderTypeList().size() > 10, "OC-01-001-01-15-004", "订单类型编码集合", request.getSalesOrderTypeList().size(), "10");
            checkItemLength(request.getSalesOrderTypeList(), 50, "订单类型编码");
            List<String> checkExistList = request.getSalesOrderTypeList().stream().filter(x ->
                            !Lists.newArrayList(ReturnOrderTypeEnum.RE_ORDER_GROUP.getCode(), ReturnOrderTypeEnum.RE_ORDER_FREE_GROUP.getCode()).contains(x))
                    .collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "订单类型编码");
        }
        if (CollectionUtils.isNotEmpty(request.getOrderStatusList())) {
            AssertUtils.isTrue(request.getOrderStatusList().size() > 10, "OC-01-001-01-15-004", "订单状态集合", request.getOrderStatusList().size(), 10);
            request.getOrderStatusList().forEach(x -> {
                AssertUtils.lengthCheck(x, 10, false, "OC-01-001-01-15-004", "订单状态");
                OrderStatus orderStatus = OrderStatus.of(Integer.valueOf(x));
                Optional.ofNullable(orderStatus).orElseThrow(() -> new FunctionException("OC-01-001-01-15-006", "订单状态"));
            });
        }
        if (CollectionUtils.isNotEmpty(request.getDeliveryMethodCodeList())) {
            AssertUtils.isTrue(request.getDeliveryMethodCodeList().size() > 10, "OC-01-001-01-15-004", "配送方式编码集合", request.getDeliveryMethodCodeList().size(), 10);
            checkItemLength(request.getDeliveryMethodCodeList(), 50, "配送方式编码");
            List<String> checkExistList = request.getDeliveryMethodCodeList().stream().filter(x -> !SalesOrderDeliveryMethodEnum.codes().contains(x)).collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "配送方式编码");
        }
        // 时间格式确认
        Map<String, String> expectedDeliveryTimeMap = AssertUtils.timeFormatCheck(request.getExpectedDeliveryBeginDate(), request.getExpectedDeliveryEndDate(), "期望交货日期（开始日期）", "期望交货日期（结束日期）", AssertUtils.TYPE_DATE);
        Map<String, String> createTimeMap = AssertUtils.timeFormatCheck(request.getCreateBeginTime(), request.getCreateEndTime(), "创建时间（开始时间）", "创建时间（结束时间）", AssertUtils.TYPE_TIME);
        Map<String, String> updateTimeMap = AssertUtils.timeFormatCheck(request.getModifyBeginTime(), request.getModifyEndTime(), "修改时间（开始时间）", "修改时间（结束时间）", AssertUtils.TYPE_TIME);
        request.setExpectedDeliveryBeginDate(expectedDeliveryTimeMap.get(AssertUtils.START_TIME));
        request.setExpectedDeliveryEndDate(expectedDeliveryTimeMap.get(AssertUtils.END_TIME));
        request.setCreateBeginTime(createTimeMap.get(AssertUtils.START_TIME));
        request.setCreateEndTime(createTimeMap.get(AssertUtils.END_TIME));
        request.setModifyBeginTime(updateTimeMap.get(AssertUtils.START_TIME));
        request.setModifyEndTime(updateTimeMap.get(AssertUtils.END_TIME));
        if (CollectionUtils.isNotEmpty(request.getOrderReasonCodeList())) {
            AssertUtils.isTrue(request.getOrderReasonCodeList().size() > 10, "OC-01-001-01-15-004", "订单原因编码集合", request.getOrderReasonCodeList().size(), 10);
            checkItemLength(request.getOrderReasonCodeList(), 50, "订单原因编码");
            List<String> checkExistList = request.getOrderReasonCodeList().stream().filter(x -> !SalesOrderReasonEnum.codes().contains(x)).collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "订单原因编码");
        }
        if (CollectionUtils.isNotEmpty(request.getShippingWarehouseCodeList())) {
            AssertUtils.isTrue(request.getShippingWarehouseCodeList().size() > 10, "OC-01-001-01-15-004", "收货仓（逻辑仓库编码）集合", request.getShippingWarehouseCodeList().size(), 10);
            checkItemLength(request.getShippingWarehouseCodeList(), 50, "收货仓（逻辑仓库编码）");
        }
        if (CollectionUtils.isNotEmpty(request.getTxWarehouseCodeList())) {
            AssertUtils.isTrue(request.getTxWarehouseCodeList().size() > 10, "OC-01-001-01-15-004", "发货仓（逻辑仓库编码）集合", request.getTxWarehouseCodeList().size(), 10);
            checkItemLength(request.getTxWarehouseCodeList(), 50, "发货仓（逻辑仓库编码）");
        }
        AssertUtils.lengthCheck(request.getTxFactoryCode(), 50, false, "OC-01-001-01-15-004", "发货工厂编码");
        AssertUtils.lengthCheck(request.getTxStockCode(), 50, false, "OC-01-001-01-15-004", "发货库存地点编码");
        AssertUtils.lengthCheck(request.getCreatorCode(), 50, false, "OC-01-001-01-15-004", "创建人工号");
        AssertUtils.lengthCheck(request.getModifierCode(), 50, false, "OC-01-001-01-15-004", "修改人工号");
        AssertUtils.lengthCheck(request.getCustomerPurchaseOrderNo(), 50, false, "OC-01-001-01-15-004", "客户采购订单号");
        if (CollectionUtils.isNotEmpty(request.getSubStatusList())) {
            AssertUtils.isTrue(request.getSubStatusList().size() > 5, "OC-01-001-01-15-004", "发货状态集合", request.getSubStatusList().size(), 5);
            checkItemLength(request.getSubStatusList(), 50, "发货状态");
            List<String> subStatusList = Arrays.asList(OrderStatus.BEFORE_DELIVERY.getCode().toString(), OrderStatus.PARTIAL_DELIVER.getCode().toString(), OrderStatus.SHIPPED.getCode().toString());
            request.getSubStatusList().forEach(a -> {
                if (!subStatusList.contains(a)) throw new FunctionException("OC-01-001-01-15-006", "发货状态");
            });
        }
        AssertUtils.lengthCheck(request.getNote(), 255, false, "OC-01-001-01-15-004", "备注（主单）");
        if (CollectionUtils.isNotEmpty(request.getProductCodeList())) {
            AssertUtils.isTrue(request.getProductCodeList().size() > 10, "OC-01-001-01-15-004", "物料编码集合", request.getProductCodeList().size(), 10);
            request.getProductCodeList().forEach(x -> AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "物料编码"));
        }
        if (StringUtils.isNotBlank(request.getIsClose())) {
            AssertUtils.lengthCheck(request.getIsClose(), 50, false, "OC-01-001-01-15-004", "是否关闭");
            AssertUtils.isTrue(!Lists.newArrayList(GeneralStatusEnum.YES.getCode().toString(), GeneralStatusEnum.NO.getCode().toString()).contains(request.getIsClose()), "OC-01-001-01-15-006", "是否关闭");
        }
        if (CollectionUtils.isNotEmpty(request.getCloseReasonCodeList())) {
            AssertUtils.isTrue(request.getCloseReasonCodeList().size() > 10, "OC-01-001-01-15-004", "关闭原因编码集合", request.getCloseReasonCodeList().size(), 10);
            checkItemLength(request.getCloseReasonCodeList(), 50, "关闭原因编码");
            List<String> checkExistList = request.getCloseReasonCodeList().stream().filter(x -> !SalesOrderCloseEnum.codes().contains(x)).collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "关闭原因编码");
        }
        AssertUtils.lengthCheck(request.getDetailNote(), 255, false, "OC-01-001-01-15-004", "订单行备注");
    }

    private void paramPageQueryCheck(ReturnOrderGroupPageQueryRequest request) {
        //必填项校验
        AssertUtils.isTrue(StringUtils.isBlank(request.getBusinessType()), "OC-01-001-01-15-001", "业态编码");
        //长度校验
        if (CollectionUtils.isNotEmpty(request.getFromSysList())) {
            AssertUtils.isTrue(request.getFromSysList().size() > 10, "OC-01-001-01-15-004", "来源系统编码集合", request.getFromSysList().size(), "10");
            checkItemLength(request.getFromSysList(), 50, "来源系统编码");
            request.getFromSysList().forEach(fromSys -> {
                dictionaryVerifyAdapter.verifyDictionary(DictionaryTypeEnum.FROM_SYS.getCode(), fromSys, new FunctionException("OC-01-001-01-15-006", "来源系统编码"));
            });
        }
        AssertUtils.lengthCheck(request.getBusinessType(), 10, true, "OC-01-001-01-15-004", "业态编码");
        List<DictionaryResponse> businessTypeResponseList = baseDataServiceAdapter.queryDictionarys(DictionaryTypeEnum.BUSINESS_TYPE.getCode());
        Map<String, DictionaryResponse> businessTypeMap = businessTypeResponseList.stream().collect(Collectors.toMap(DictionaryResponse::getCode, Function.identity(), (k1, k2) -> k2));
        if (Objects.isNull(businessTypeMap.get(request.getBusinessType()))) {
            throw new FunctionException("OC-01-001-01-15-006", "业态编码");
        }
        if (CollectionUtils.isNotEmpty(request.getBusinessUnitCodeList())) {
            AssertUtils.isTrue(request.getBusinessUnitCodeList().size() > 10, "OC-01-001-01-15-004", "业务单元编码集合", request.getBusinessUnitCodeList().size(), "10");
            checkItemLength(request.getBusinessUnitCodeList(), 50, "业务单元编码");
            request.getBusinessUnitCodeList().forEach(businessUnitCode -> {
                dictionaryVerifyAdapter.verifyDictionary(DictionaryTypeEnum.BUSINESS_UNIT_CODE.getCode(), businessUnitCode, new FunctionException("OC-01-001-01-15-006", "业务单元编码"));
            });
        }
        if (Objects.nonNull(request.getPage())) {
            AssertUtils.isTrue(request.getPage() > MnOrderCenterConstants.MAX_PAGE().intValue(), "OC-01-001-01-15-009", "页数", "最大" + MnOrderCenterConstants.MAX_PAGE().intValue());
            AssertUtils.isTrue(request.getPage() <= 0, "OC-01-001-01-15-009", "页数", "最小值为1");
        }
        if (Objects.nonNull(request.getSize())) {
            AssertUtils.isTrue(request.getSize() > MnOrderCenterConstants.MAX_SIZE().intValue(), "OC-01-001-01-15-009", "分页条数", "最大" + MnOrderCenterConstants.MAX_SIZE().intValue());
            AssertUtils.isTrue(request.getSize() <= 0, "OC-01-001-01-15-009", "分页条数", "最小值为1");
        }
        if (CollectionUtils.isNotEmpty(request.getOrderChannelCodeList())) {
            AssertUtils.isTrue(request.getOrderChannelCodeList().size() > 10, "OC-01-001-01-15-004", "订单渠道编码集合", request.getOrderChannelCodeList().size(), "10");
            checkItemLength(request.getOrderChannelCodeList(), 50, "订单渠道编码");
            List<String> checkExistList = request.getOrderChannelCodeList().stream().filter(x -> !OrderChannelEnum.codes().contains(x)).collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "订单渠道编码");
        }
        if (CollectionUtils.isNotEmpty(request.getSalesOrderNoList())) {
            AssertUtils.isTrue(request.getSalesOrderNoList().size() > 50, "OC-01-001-01-15-004", "退货订单号集合", request.getSalesOrderNoList().size(), 50);
            checkItemLength(request.getSalesOrderNoList(), 50, "退货订单号");
        }
        if (CollectionUtils.isNotEmpty(request.getOriginalOrderNoList())) {
            AssertUtils.isTrue(request.getOriginalOrderNoList().size() > 50, "OC-01-001-01-15-004", "原销售订单单号集合", request.getOriginalOrderNoList().size(), 50);
            request.getOriginalOrderNoList().forEach(x -> AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "原销售订单单号"));
        }
        if (CollectionUtils.isNotEmpty(request.getSourceOrderNoList())) {
            AssertUtils.isTrue(request.getSourceOrderNoList().size() > 50, "OC-01-001-01-15-004", "来源单号集合", request.getSourceOrderNoList().size(), 50);
            request.getSourceOrderNoList().forEach(x -> AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "来源单号"));
        }
        if (CollectionUtils.isNotEmpty(request.getOutOrderNoList())) {
            AssertUtils.isTrue(request.getOutOrderNoList().size() > 50, "OC-01-001-01-15-004", "外部单号集合", request.getOutOrderNoList().size(), 50);
            request.getOutOrderNoList().forEach(x -> AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "外部单号"));
        }
        AssertUtils.lengthCheck(request.getProductGroupCode(), 50, false, "OC-01-001-01-15-004", "产品组编码");
        AssertUtils.lengthCheck(request.getBusinessChannelCode(), 50, false, "OC-01-001-01-15-004", "业务渠道编码");
        AssertUtils.lengthCheck(request.getSalesOrganizationCode(), 50, false, "OC-01-001-01-15-004", "销售组织编码");
        AssertUtils.lengthCheck(request.getShipToPartyCode(), 50, false, "OC-01-001-01-15-004", "送达方编码");
        AssertUtils.lengthCheck(request.getCustomerCode(), 50, false, "OC-01-001-01-15-004", "售达方编码");
        if (CollectionUtils.isNotEmpty(request.getSalesChannelCodeList())) {
            AssertUtils.isTrue(request.getSalesChannelCodeList().size() > 10, "OC-01-001-01-15-004", "销售渠道编码集合", request.getSalesChannelCodeList().size(), 10);
            request.getSalesChannelCodeList().forEach(x -> {
                AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "销售渠道编码");
            });
        }
        if (CollectionUtils.isNotEmpty(request.getSalesDepartmentCodeList())) {
            AssertUtils.isTrue(request.getSalesDepartmentCodeList().size() > 10, "OC-01-001-01-15-004", "销售部门编码集合", request.getSalesDepartmentCodeList().size(), 10);
            request.getSalesDepartmentCodeList().forEach(x -> {
                AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "销售部门编码");
            });
        }
        AssertUtils.lengthCheck(request.getCustomerGroup(), 50, false, "OC-01-001-01-15-004", "客户组编码");
        if (CollectionUtils.isNotEmpty(request.getSalesOrderTypeList())) {
            AssertUtils.isTrue(request.getSalesOrderTypeList().size() > 10, "OC-01-001-01-15-004", "订单类型编码集合", request.getSalesOrderTypeList().size(), "10");
            checkItemLength(request.getSalesOrderTypeList(), 10, "订单类型编码");
            List<String> checkExistList = request.getSalesOrderTypeList().stream().filter(x ->
                            !Lists.newArrayList(ReturnOrderTypeEnum.RE_ORDER_GROUP.getCode(), ReturnOrderTypeEnum.RE_ORDER_FREE_GROUP.getCode()).contains(x))
                    .collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "订单类型编码");
        }
        if (CollectionUtils.isNotEmpty(request.getOrderStatusList())) {
            AssertUtils.isTrue(request.getOrderStatusList().size() > 10, "OC-01-001-01-15-004", "订单状态集合", request.getOrderStatusList().size(), 10);
            request.getOrderStatusList().forEach(x -> {
                AssertUtils.lengthCheck(x, 10, false, "OC-01-001-01-15-004", "订单状态");
                AssertUtils.isTrue(new BigDecimal("2147483647").compareTo(new BigDecimal(x)) < 0, "OC-01-001-01-15-009", "订单状态", "最大2147483647");
                OrderStatus orderStatus = OrderStatus.of(Integer.valueOf(x));
                Optional.ofNullable(orderStatus).orElseThrow(() -> new FunctionException("OC-01-001-01-15-006", "订单状态"));
            });
        }
        if (CollectionUtils.isNotEmpty(request.getDeliveryMethodCodeList())) {
            AssertUtils.isTrue(request.getDeliveryMethodCodeList().size() > 10, "OC-01-001-01-15-004", "配送方式编码集合", request.getDeliveryMethodCodeList().size(), 10);
            checkItemLength(request.getDeliveryMethodCodeList(), 50, "配送方式编码");
            List<String> checkExistList = request.getDeliveryMethodCodeList().stream().filter(x -> !SalesOrderDeliveryMethodEnum.codes().contains(x)).collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "配送方式编码");
        }
        // 时间格式确认
        Map<String, String> expectedDeliveryTimeMap = AssertUtils.timeFormatCheck(request.getExpectedDeliveryBeginDate(), request.getExpectedDeliveryEndDate(), "期望交货日期（开始日期）", "期望交货日期（结束日期）", AssertUtils.TYPE_DATE);
        Map<String, String> createTimeMap = AssertUtils.timeFormatCheck(request.getCreateBeginTime(), request.getCreateEndTime(), "创建时间（开始时间）", "创建时间（结束时间）", AssertUtils.TYPE_TIME);
        Map<String, String> updateTimeMap = AssertUtils.timeFormatCheck(request.getModifyBeginTime(), request.getModifyEndTime(), "修改时间（开始时间）", "修改时间（结束时间）", AssertUtils.TYPE_TIME);
        request.setExpectedDeliveryBeginDate(expectedDeliveryTimeMap.get(AssertUtils.START_TIME));
        request.setExpectedDeliveryEndDate(expectedDeliveryTimeMap.get(AssertUtils.END_TIME));
        request.setCreateBeginTime(createTimeMap.get(AssertUtils.START_TIME));
        request.setCreateEndTime(createTimeMap.get(AssertUtils.END_TIME));
        request.setModifyBeginTime(updateTimeMap.get(AssertUtils.START_TIME));
        request.setModifyEndTime(updateTimeMap.get(AssertUtils.END_TIME));

        AssertUtils.lengthCheck(request.getFulfillmentTypeCode(), 50, false, "OC-01-001-01-15-004", "履约方式");
        if (StringUtils.isNotBlank(request.getFulfillmentTypeCode())) {
            List<DictionaryResponse> fulfillmentTypeList = baseDataServiceAdapter.queryDictionarys(DictionaryTypeEnum.GROUP_RETURN_FULFILLMENT_TYPE.getCode());
            Map<String, DictionaryResponse> fulfillmentTypeMap = fulfillmentTypeList.stream().collect(Collectors.toMap(DictionaryResponse::getCode, Function.identity(), (k1, k2) -> k2));
            DictionaryResponse dictionaryResponse = fulfillmentTypeMap.get(request.getFulfillmentTypeCode());
            Optional.ofNullable(dictionaryResponse).orElseThrow(() -> new FunctionException("OC-01-001-01-15-006", "履约方式编码"));
        }
        //校验履约优先级
        AssertUtils.lengthCheck(request.getFulfillmentPriority(), 10, false, "OC-01-001-01-15-004", "履约优先级");
        if (StringUtils.isNotBlank(request.getFulfillmentPriority())) {
            FulfillmentPriorityEnum fulfillmentPriorityEnum = FulfillmentPriorityEnum.of(request.getFulfillmentPriority());
            Optional.ofNullable(fulfillmentPriorityEnum).orElseThrow(() -> new FunctionException("OC-01-001-01-15-006", "履约优先级"));
        }
        AssertUtils.isBoolean(request.getAutoFulfillment(), false, "是否自动创建履约单");
        if (StringUtils.isNotBlank(request.getOrderBizTag())) {
            AssertUtils.lengthCheck(request.getOrderBizTag(), 50, false, "OC-01-001-01-15-004", "订单标签");
            OrderBizTagEnum orderBizTagEnum = OrderBizTagEnum.of(request.getOrderBizTag());
            Optional.ofNullable(orderBizTagEnum).orElseThrow(() -> new FunctionException("OC-01-001-01-15-006", "订单标签"));
        }
        if (CollectionUtils.isNotEmpty(request.getOrderReasonCodeList())) {
            AssertUtils.isTrue(request.getOrderReasonCodeList().size() > 10, "OC-01-001-01-15-004", "订单原因编码集合", request.getOrderReasonCodeList().size(), 10);
            checkItemLength(request.getOrderReasonCodeList(), 50, "订单原因编码");
            List<String> checkExistList = request.getOrderReasonCodeList().stream().filter(x -> !SalesOrderReasonEnum.codes().contains(x)).collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "订单原因编码");
        }
        if (CollectionUtils.isNotEmpty(request.getShippingWarehouseCodeList())) {
            AssertUtils.isTrue(request.getShippingWarehouseCodeList().size() > 10, "OC-01-001-01-15-004", "收货仓（逻辑仓库编码）集合", request.getShippingWarehouseCodeList().size(), 10);
            checkItemLength(request.getShippingWarehouseCodeList(), 50, "收货仓（逻辑仓库编码）");
        }
        if (CollectionUtils.isNotEmpty(request.getTxWarehouseCodeList())) {
            AssertUtils.isTrue(request.getTxWarehouseCodeList().size() > 10, "OC-01-001-01-15-004", "发货仓（逻辑仓库编码）集合", request.getTxWarehouseCodeList().size(), 10);
            checkItemLength(request.getTxWarehouseCodeList(), 50, "发货仓（逻辑仓库编码）");
        }
        AssertUtils.lengthCheck(request.getTxFactoryCode(), 50, false, "OC-01-001-01-15-004", "发货工厂编码");
        AssertUtils.lengthCheck(request.getTxStockCode(), 50, false, "OC-01-001-01-15-004", "发货库存地点编码");
        AssertUtils.lengthCheck(request.getCreatorCode(), 50, false, "OC-01-001-01-15-004", "创建人工号");
        AssertUtils.lengthCheck(request.getModifierCode(), 50, false, "OC-01-001-01-15-004", "修改人工号");
        AssertUtils.lengthCheck(request.getCustomerPurchaseOrderNo(), 50, false, "OC-01-001-01-15-004", "客户采购订单号");
        if (CollectionUtils.isNotEmpty(request.getSubStatusList())) {
            AssertUtils.isTrue(request.getSubStatusList().size() > 5, "OC-01-001-01-15-004", "发货状态集合", request.getSubStatusList().size(), 5);
            checkItemLength(request.getSubStatusList(), 50, "发货状态");
            List<String> subStatusList = Arrays.asList(OrderStatus.BEFORE_DELIVERY.getCode().toString(), OrderStatus.PARTIAL_DELIVER.getCode().toString(), OrderStatus.SHIPPED.getCode().toString());
            request.getSubStatusList().forEach(a -> {
                if (!subStatusList.contains(a)) throw new FunctionException("OC-01-001-01-15-006", "发货状态");
            });
        }
        AssertUtils.lengthCheck(request.getNote(), 255, false, "OC-01-001-01-15-004", "备注（主单）");
        if (CollectionUtils.isNotEmpty(request.getProductCodeList())) {
            AssertUtils.isTrue(request.getProductCodeList().size() > 10, "OC-01-001-01-15-004", "物料编码集合", request.getProductCodeList().size(), 10);
            request.getProductCodeList().forEach(x -> AssertUtils.lengthCheck(x, 50, false, "OC-01-001-01-15-004", "物料编码"));
        }
        if (CollectionUtils.isNotEmpty(request.getCloseReasonCodeList())) {
            AssertUtils.isTrue(request.getCloseReasonCodeList().size() > 10, "OC-01-001-01-15-004", "关闭原因编码集合", request.getCloseReasonCodeList().size(), 10);
            checkItemLength(request.getCloseReasonCodeList(), 50, "关闭原因编码");
            List<String> checkExistList = request.getCloseReasonCodeList().stream().filter(x -> !SalesOrderCloseEnum.codes().contains(x)).collect(Collectors.toList());
            AssertUtils.isTrue(CollectionUtils.isNotEmpty(checkExistList), "OC-01-001-01-15-006", "关闭原因编码");
        }
    }

    private void checkItemLength(List<String> items, Integer maxLength, String errMsg) {
        items.forEach(x -> {
            AssertUtils.lengthCheck(x, maxLength, false, "OC-01-001-01-15-004", errMsg);
        });
    }

    private void paramQueryCheck(QueryReturnOrderRequest request) {
        //必填项校验
        AssertUtils.isTrue(StringUtils.isBlank(request.getBusinessType()), "OC-01-001-01-15-001", "业态编码");
        AssertUtils.isTrue(StringUtils.isBlank(request.getSalesOrderNo()), "OC-01-001-01-15-001", "退货订单单号");
        //长度校验
        AssertUtils.lengthCheck(request.getFromSys(), 50, false, "OC-01-001-01-15-004", "来源系统编码");
        AssertUtils.lengthCheck(request.getBusinessType(), 10, true, "OC-01-001-01-15-004", "业态编码");
        AssertUtils.lengthCheck(request.getBusinessUnitCode(), 50, false, "OC-01-001-01-15-004", "业务单元编码");
        AssertUtils.lengthCheck(request.getSalesOrderNo(), 50, true, "OC-01-001-01-15-004", "退货订单单号");
        //枚举校验

        // 系统来源
        if (StringUtils.isNotBlank(request.getFromSys())) {
            List<DictionaryResponse> fromSysResponseList = baseDataServiceAdapter.queryDictionarys(DictionaryTypeEnum.FROM_SYS.getCode());
            Map<String, DictionaryResponse> fromSysMap = fromSysResponseList.stream().collect(Collectors.toMap(DictionaryResponse::getCode, Function.identity(), (k1, k2) -> k2));
            if (Objects.isNull(fromSysMap.get(request.getFromSys()))) {
                throw new FunctionException("OC-01-001-01-15-006", "来源系统编码");
            }
        }
        //业态
        List<DictionaryResponse> businessTypeResponseList = baseDataServiceAdapter.queryDictionarys(DictionaryTypeEnum.BUSINESS_TYPE.getCode());
        Map<String, DictionaryResponse> businessTypeMap = businessTypeResponseList.stream().collect(Collectors.toMap(DictionaryResponse::getCode, Function.identity(), (k1, k2) -> k2));
        if (Objects.isNull(businessTypeMap.get(request.getBusinessType()))) {
            throw new FunctionException("OC-01-001-01-15-006", "业态编码");
        }
        //业务单元编码
        if (StringUtils.isNotBlank(request.getBusinessUnitCode())) {
            List<DictionaryResponse> businessUnitCodeResponseList = baseDataServiceAdapter.queryDictionarys(DictionaryTypeEnum.BUSINESS_UNIT_CODE.getCode());
            Map<String, DictionaryResponse> businessUnitCodeMap = businessUnitCodeResponseList.stream().collect(Collectors.toMap(DictionaryResponse::getCode, Function.identity(), (k1, k2) -> k2));
            if (Objects.isNull(businessUnitCodeMap.get(request.getBusinessUnitCode()))) {
                throw new FunctionException("OC-01-001-01-15-006", "业务单元编码");
            }
        }
    }

    @NotNull
    private PageQueryOrderEsListRequest4OrderCenter buildPageQueryOrderEsListRequest(SalesOrderAtomPageQueryRequest pageRequest) {
        PageQueryOrderEsListRequest4OrderCenter esRequest = new PageQueryOrderEsListRequest4OrderCenter();
        esRequest.setDir("main_gmt_create");
        String fromSys = pageRequest.getFromSys();
        String businessType = pageRequest.getBusinessType();
        String businessUnitCode = pageRequest.getBusinessUnitCode();
        String createTimeStart = pageRequest.getCreateBeginTime();
        String createTimeEnd = pageRequest.getCreateEndTime();
        List<String> salesOrderType = pageRequest.getSalesOrderType();
        String customerCode = pageRequest.getCustomerCode();
        String shipToPartyCode = pageRequest.getShipToPartyCode();
        String salesOrganizationCode = pageRequest.getSalesOrganizationCode();
        List<String> salesChannelCode = pageRequest.getSalesChannelCode();
        List<String> salesDepartmentCode = pageRequest.getSalesDepartmentCode();
        String productGroupCode = pageRequest.getProductGroupCode();
        List<String> businessChannel = pageRequest.getBusinessChannel();

        //一盘货改造
        List<String> fromSysList = pageRequest.getFromSysList();
        List<String> businessUnitCodeList = pageRequest.getBusinessUnitCodeList();
        String preOrderNo = pageRequest.getPreOrderNo();
        List<String> sourceOrderNoList = pageRequest.getSourceOrderNoList();
        String businessChannelCode = pageRequest.getBusinessChannelCode();
        List<String> statusList = pageRequest.getStatusList();
        String expectedDeliveryBeginTime = pageRequest.getExpectedDeliveryBeginDate();
        String expectedDeliveryEndTime = pageRequest.getExpectedDeliveryEndDate();
//        String vaildBeginTime = pageRequest.getVaildBeginTime();
//        String validEndTime = pageRequest.getValidEndTime();
        String updateBeginTime = pageRequest.getModifyBeginTime();
        String updateEndTime = pageRequest.getModifyEndTime();
        List<String> deliveryMethodCodeList = pageRequest.getDeliveryMethodCodeList();
        String note = pageRequest.getNote();
        String customerPurchaseOrderNo = pageRequest.getCustomerPurchaseOrderNo();
        List<String> orderReasonCodeList = pageRequest.getOrderReasonCodeList();
        List<String> receiveWarehouseCodeList = pageRequest.getReceiveWarehouseCodeList();
        String deliveryFactoryCode = pageRequest.getDeliveryFactoryCode();
        String stockCode = pageRequest.getStockCode();
        List<String> shippingWarehouseCodeList = pageRequest.getShippingWarehouseCodeList();
        String contact = pageRequest.getContact();
        String contactPhone = pageRequest.getContactPhone();
        List<String> closeReasonCodeList = pageRequest.getCloseReasonCodeList();
        List<String> productCodeList = pageRequest.getProductCodeList();
        List<String> orderChannelCodeList = pageRequest.getOrderChannelCodeList();
        String salesOrderNo = pageRequest.getSalesOrderNo();
        String customerGrade = pageRequest.getCustomerGrade();
        String customerGroup = pageRequest.getCustomerGroup();
        String fulfillmentTypeCode = pageRequest.getFulfillmentTypeCode();
        String fulfillmentPriority = pageRequest.getFulfillmentPriority();
        String orderTag = pageRequest.getOrderTag();
        String receiveStatus = pageRequest.getReceiveStatus();
        String creatorCode = pageRequest.getCreatorCode();
        List<String> outOrderNoList = pageRequest.getOutOrderNoList();
        List<String> kaSystemList = pageRequest.getKaSystemList();
        List<String> kaAreaList = pageRequest.getKaAreaList();
        String sourceBeginTime = pageRequest.getSourceBeginTime();
        String sourceEndTime = pageRequest.getSourceEndTime();
        String originalOrderNo = pageRequest.getOriginalOrderNo();
        String autoFulfillment = pageRequest.getAutoFulfillment();
        String receiveStockCode = pageRequest.getReceiveStockCode();
        String receiveFactoryCode = pageRequest.getReceiveFactoryCode();
        List<String> subStatusList = pageRequest.getSubStatusList();
        List<String> originalOrderNoList = pageRequest.getOriginalOrderNoList();

        if (StringUtils.isNotBlank(pageRequest.getModifierCode())) {
            esRequest.setModifierCode(pageRequest.getModifierCode());
        }
        if (StringUtils.isNotBlank(pageRequest.getOrderCategoryCode())) {
            esRequest.setOrderCategoryCode(pageRequest.getOrderCategoryCode());
        }
        if (CollectionUtils.isNotEmpty(pageRequest.getOrderCategoryCodeList())) {
            esRequest.setOrderCategoryCodeList(pageRequest.getOrderCategoryCodeList());
        }
        if (CollectionUtils.isNotEmpty(pageRequest.getSalesOrderNoList())) {
            esRequest.setBizCodeList(pageRequest.getSalesOrderNoList());
        }
        if (CollectionUtils.isNotEmpty(pageRequest.getPreOrderNoList())) {
            esRequest.setPreOrderNoList(pageRequest.getPreOrderNoList());
        }
        if (StringUtils.isNotBlank(pageRequest.getOrderTag())) {
            esRequest.setOrderTag(pageRequest.getOrderTag());
        }
        if (StringUtils.isNotBlank(pageRequest.getOrderBizTag())) {
            esRequest.setOrderBizTag(pageRequest.getOrderBizTag());
        }
        if (StringUtils.isNotBlank(fromSys)) {
            esRequest.setFromSys(fromSys);
        }
        if (StringUtils.isNotBlank(businessType)) {
            esRequest.setBusinessType(businessType);
        }
        if (StringUtils.isNotBlank(businessUnitCode)) {
            esRequest.setBusinessUnitCode(businessUnitCode);
        }
        try {
            if (StringUtils.isNotBlank(createTimeStart)) {
                esRequest.setOrderStartTime(DateUtils.formatString2Date(createTimeStart, "yyyy-MM-dd HH:mm:ss"));
            }
            if (StringUtils.isNotBlank(createTimeEnd)) {
                esRequest.setOrderEndTime(DateUtils.formatString2Date(createTimeEnd, "yyyy-MM-dd HH:mm:ss"));
            }
            if (StringUtils.isNotBlank(updateBeginTime)) {
                esRequest.setUpdateStartTime(DateUtils.formatString2Date(updateBeginTime, "yyyy-MM-dd HH:mm:ss"));
            }
            if (StringUtils.isNotBlank(updateEndTime)) {
                esRequest.setUpdateEndTime(DateUtils.formatString2Date(updateEndTime, "yyyy-MM-dd HH:mm:ss"));
            }
            if (StringUtils.isNotBlank(expectedDeliveryBeginTime)) {
                esRequest.setExpectedDeliveryBeginTime(DateUtils.formatString2Date(expectedDeliveryBeginTime, "yyyy-MM-dd"));
            }
            if (StringUtils.isNotBlank(expectedDeliveryEndTime)) {
                esRequest.setExpectedDeliveryEndTime(DateUtils.formatString2Date(expectedDeliveryEndTime, "yyyy-MM-dd"));
            }
//            if (StringUtils.isNotBlank(vaildBeginTime)) {
//                esRequest.setVaildBeginTime(DateUtils.formatString2Date(vaildBeginTime, "yyyy-MM-dd"));
//            }
//            if (StringUtils.isNotBlank(validEndTime)) {
//                esRequest.setValidEndTime(DateUtils.formatString2Date(validEndTime, "yyyy-MM-dd"));
//            }
        } catch (Exception e) {
            log.error("ExchangeOrderAtomQueryServiceImpl#buildPageQueryOrderEsListRequest error", e);
            throw new FunctionException("OC-00-001-01-15-001", "日期");
        }
        if (StringUtils.isNotBlank(creatorCode)) {
            esRequest.setCreatorCode(creatorCode);
        }
        if (CollectionUtils.isNotEmpty(salesOrderType)) {
            esRequest.setOrderTypeList(salesOrderType);
        }
        if (StringUtils.isNotBlank(customerCode)) {
            esRequest.setCustomerCode(customerCode);
        }
        if (StringUtils.isNotBlank(shipToPartyCode)) {
            esRequest.setAddressCode(shipToPartyCode);
        }
        if (StringUtils.isNotBlank(shipToPartyCode)) {
            esRequest.setAddressCode(shipToPartyCode);
        }
        if (StringUtils.isNotBlank(salesOrganizationCode)) {
            esRequest.setSalesOrganizationOutCode(salesOrganizationCode);
        }
        if (CollectionUtils.isNotEmpty(salesChannelCode)) {
            esRequest.setSaleChannelOutCode(salesChannelCode);
        }
        if (CollectionUtils.isNotEmpty(salesDepartmentCode)) {
            esRequest.setSaleDepartmentOutCode(salesDepartmentCode);
        }
        if (StringUtils.isNotBlank(productGroupCode)) {
            esRequest.setProductGroupCode(productGroupCode);
        }
        if (CollectionUtils.isNotEmpty(businessChannel)) {
            esRequest.setBuzChannel(businessChannel);
        }
        if (CollectionUtils.isNotEmpty(fromSysList)) {
            esRequest.setFromSysList(fromSysList);
        }
        if (CollectionUtils.isNotEmpty(businessUnitCodeList)) {
            esRequest.setBusinessUnitCodeList(businessUnitCodeList);
        }
        if (StringUtils.isNotBlank(preOrderNo)) {
            esRequest.setPreOrderNo(preOrderNo);
        }
        if (CollectionUtils.isNotEmpty(sourceOrderNoList)) {
            esRequest.setSourceOrderNoList(sourceOrderNoList);
        }
        if (StringUtils.isNotBlank(productGroupCode)) {
            esRequest.setProductGroupCode(productGroupCode);
        }
        if (StringUtils.isNotBlank(businessChannelCode)) {
            esRequest.setBusinessChannelCode(businessChannelCode);
        }
        if (CollectionUtils.isNotEmpty(statusList)) {
            esRequest.setMainStatusList(statusList);
        }
        if (CollectionUtils.isNotEmpty(deliveryMethodCodeList)) {
            esRequest.setDeliveryMethodCodeList(deliveryMethodCodeList);
        }
        if (StringUtils.isNotBlank(note)) {
            esRequest.setOrderRemark(note);
        }
        if (StringUtils.isNotBlank(customerPurchaseOrderNo)) {
            esRequest.setCustomerPurchaseOrderNo(customerPurchaseOrderNo);
        }
        if (CollectionUtils.isNotEmpty(orderReasonCodeList)) {
            esRequest.setOrderReasonCodeList(orderReasonCodeList);
        }
        if (CollectionUtils.isNotEmpty(receiveWarehouseCodeList)) {
            esRequest.setReceiveWarehouseCodeList(receiveWarehouseCodeList);
        }
        if (StringUtils.isNotBlank(deliveryFactoryCode)) {
            esRequest.setDeliveryFactoryCode(deliveryFactoryCode);
        }
        if (StringUtils.isNotBlank(stockCode)) {
            esRequest.setStockCode(stockCode);
        }
        if (CollectionUtils.isNotEmpty(shippingWarehouseCodeList)) {
            esRequest.setShippingWarehouseCodeList(shippingWarehouseCodeList);
        }
        if (StringUtils.isNotBlank(contact)) {
            esRequest.setContactor(contact);
        }
        if (StringUtils.isNotBlank(contactPhone)) {
            esRequest.setPhone(contactPhone);
        }
        if (CollectionUtils.isNotEmpty(closeReasonCodeList)) {
            esRequest.setCloseReasonCodeList(closeReasonCodeList);
        }
        if (CollectionUtils.isNotEmpty(productCodeList)) {
            esRequest.setProductCodeList(productCodeList);
        }
        if (CollectionUtils.isNotEmpty(orderChannelCodeList)) {
            esRequest.setOrderChannelCodeList(orderChannelCodeList);
        }
        if (StringUtils.isNotBlank(salesOrderNo)) {
            esRequest.setOrderBizId(salesOrderNo);
        }
        if (StringUtils.isNotBlank(customerGrade)) {
            esRequest.setCustomerGrade(customerGrade);
        }
        if (StringUtils.isNotBlank(customerGroup)) {
            esRequest.setCustomerGroup(customerGroup);
        }
        if (StringUtils.isNotBlank(fulfillmentTypeCode)) {
            esRequest.setFulfillmentTypeCode(fulfillmentTypeCode);
        }
        if (StringUtils.isNotBlank(fulfillmentPriority)) {
            esRequest.setFulfillmentPriority(fulfillmentPriority);
        }
        if (StringUtils.isNotBlank(orderTag)) {
            esRequest.setOrderTag(orderTag);
        }
        if (CollectionUtils.isNotEmpty(outOrderNoList)) {
            esRequest.setOuterIdList(outOrderNoList);
        }
        if (CollectionUtils.isNotEmpty(kaSystemList)) {
            esRequest.setKaSystemList(kaSystemList);
        }
        if (CollectionUtils.isNotEmpty(kaAreaList)) {
            esRequest.setKaAreaList(kaAreaList);
        }
        if (StringUtils.isNotBlank(sourceBeginTime)) {
            esRequest.setSourceBeginTime(sourceBeginTime);
        }
        if (StringUtils.isNotBlank(sourceEndTime)) {
            esRequest.setSourceEndTime(sourceEndTime);
        }

        if (StringUtils.isNotBlank(originalOrderNo)) {
            esRequest.setOriginalOrderNo(originalOrderNo);
        }
        if (StringUtils.isNotBlank(autoFulfillment)) {
            esRequest.setAutoFulfillment(autoFulfillment);
        }
        if (StringUtils.isNotBlank(receiveStockCode)) {
            esRequest.setReceiveStockCode(receiveStockCode);
        }
        if (StringUtils.isNotBlank(receiveFactoryCode)) {
            esRequest.setReceiveFactoryCode(receiveFactoryCode);
        }
        if (CollectionUtils.isNotEmpty(subStatusList)) {
            esRequest.setSubStatusList(subStatusList);
        }
        if (CollectionUtils.isNotEmpty(originalOrderNoList)) {
            esRequest.setOriginalOrderNoList(originalOrderNoList);
        }
        esRequest.setPage(pageRequest.getPage());
        esRequest.setSize(pageRequest.getSize());
        esRequest.setLimit(pageRequest.getSize());

        return esRequest;
    }
}
